using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_Shop__PayInfo : Member, IRequiresSessionState
{
	protected HtmlInputText pay_name;
	protected TextBox pay_desc;
	protected Label Label_AlipayAccount;
	protected HtmlInputText alipay_account;
	protected HtmlTableRow tr1_1;
	protected Label Label_AlipayKey;
	protected HtmlInputText alipay_key;
	protected HtmlTableRow tr1_2;
	protected Label Label_Account;
	protected HtmlInputText sh_account;
	protected HtmlTableRow tr2_1;
	protected Label Label_Key;
	protected HtmlInputText sh_key;
	protected HtmlTableRow tr2_2;
	protected HtmlInputText pay_fee;
	protected CheckBox ChDisable;
	protected Button Button_Ok;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.InitPage();
		}
	}
	protected void InitPage()
	{
		if (base.Request.QueryString["pid"] == "1")
		{
			this.tr1_1.Visible = true;
			this.tr1_2.Visible = true;
			this.tr2_1.Visible = true;
			this.tr2_2.Visible = false;
		}
		else
		{
			this.tr1_1.Visible = false;
			this.tr1_2.Visible = false;
			this.tr2_1.Visible = true;
			this.tr2_2.Visible = true;
		}
		string text = base.Request.QueryString["pid"].ToString();
		if (text != null)
		{
			if (text == "1")
			{
				this.Label_AlipayAccount.Text = "支付宝帐号：";
				this.Label_AlipayKey.Text = "交易安全校验码(key)：";
				this.Label_Account.Text = "合作者身份(partnerID)：";
				goto IL_19E;
			}
			if (text == "2")
			{
				this.Label_Account.Text = "贝宝帐号：";
				this.Label_Key.Text = "贝宝公共密钥：";
				goto IL_19E;
			}
			if (text == "4")
			{
				this.Label_Account.Text = "商户编号：";
				this.Label_Key.Text = "快钱密钥：";
				goto IL_19E;
			}
		}
		this.Label_Account.Text = "商户号：";
		this.Label_Key.Text = "商户密钥：";
		IL_19E:
		string onlinePay = base.Request.QueryString["doPost"].ToString();
		string a = "";
		if (base.Request.QueryString["state"] != null)
		{
			a = base.Request.QueryString["state"].ToString();
		}
		if (a == "Edit")
		{
			Shop_PayType shop_PayType = new Shop_PayType();
			DataTable payTypeByOnlinePay = shop_PayType.GetPayTypeByOnlinePay(onlinePay);
			DataRow dataRow = payTypeByOnlinePay.Rows[0];
			this.pay_name.Value = dataRow["TypeName"].ToString();
			this.pay_desc.Text = dataRow["Intro"].ToString();
			this.alipay_account.Value = dataRow["PayAccount"].ToString();
			this.sh_account.Value = dataRow["BussinessCount"].ToString();
			this.pay_fee.Value = dataRow["Discount"].ToString();
			this.ChDisable.Checked = Convert.ToBoolean(dataRow["IsDisabled"]);
		}
	}
	protected void Button_Ok_Click(object sender, EventArgs e)
	{
		Shop_PayType shop_PayType = new Shop_PayType();
		string typeName = this.pay_name.Value.Replace("'", "").Replace("\"", "");
		string text = "";
		bool isDefault = false;
		string text2 = base.Request.QueryString["doPost"].ToString();
		decimal discount = int.Parse(this.pay_fee.Value);
		string value = this.sh_account.Value;
		int userID = base.user.UserID;
		string value2 = this.alipay_account.Value;
		string bussinesMD5Key = this.alipay_key.Value;
		if (text2 != "Alipay")
		{
			bussinesMD5Key = this.sh_key.Value;
		}
		bool @checked = this.ChDisable.Checked;
		string text3 = this.pay_desc.Text;
		int payType = 0;
		string a = "";
		if (base.Request.QueryString["state"] != null)
		{
			a = base.Request.QueryString["state"].ToString();
		}
		if (a == "Edit")
		{
			string sql = "SELECT TypeID,BussinesMD5Key From [HLShop_PayType] Where OnlinePay='" + text2 + "'";
			DataTable dataTable = this.conn.GetDataTable(sql);
			int typeID = Convert.ToInt32(dataTable.Rows[0]["TypeID"]);
			if (text2 != "Alipay" && this.sh_key.Value.Trim() != "")
			{
				bussinesMD5Key = this.sh_key.Value;
			}
			else
			{
				if (text2 == "Alipay" && this.alipay_key.Value.Trim() != "")
				{
					bussinesMD5Key = this.alipay_key.Value;
				}
				else
				{
					bussinesMD5Key = dataTable.Rows[0]["BussinesMD5Key"].ToString();
				}
			}
			if (shop_PayType.UpdatePayType(text2, discount, typeName, userID, value2, bussinesMD5Key, value, text, @checked, text3, payType, typeID))
			{
				this.WriteSuccessMsg("", "编辑成功！", "Shop_PaymentType.aspx");
			}
			else
			{
				this.WriteErrMsg("", "编辑失败！", "");
			}
		}
		else
		{
			if (shop_PayType.AddPayType(text2, discount, typeName, userID, value2, bussinesMD5Key, value, text, isDefault, @checked, text3, payType))
			{
				this.WriteSuccessMsg("", Language.GetMemberMsg("Common/AddSuccess", new string[0]), "Shop_PaymentType.aspx");
			}
			else
			{
				this.WriteErrMsg("", Language.GetMemberMsg("Common/AddFail", new string[]
				{
					""
				}), "");
			}
		}
	}
}
